package com.service.impl;

import com.bean.Log;
import com.mapper.LogMapper;
import com.service.LogService;
import com.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    @Override
    public Log getLogById(Integer logId) {
        return logMapper.getLogById(logId);
    }

    @Override
    public PageInfo<Log> getLogsWithKeyword(String keyword, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<Log> logs = logMapper.getLogsWithKeyword(keyword, offset, pageSize);
        int total = logMapper.countLogsWithKeyword(keyword);
        return new PageInfo<>(pageNum, pageSize, total, logs);
    }

    @Override
    public boolean insertLog(Log log) {
        int result = logMapper.insertLog(log);
        return result > 0;
    }

    @Override
    public boolean updateLog(Log log) {
        int result = logMapper.updateLog(log);
        return result > 0;
    }

    @Override
    public boolean deleteLogById(Integer logId) {
        int result = logMapper.deleteLogById(logId);
        return result > 0;
    }
}